$(document).ready(function() {
    $(".stu-register").hide();
    $(".tea-register").hide();
    $("#tt").bind("click", qq);
    $("#fadeIn").bind("click", slideDown);
    $("#fadeOut").bind("click", slideUp);
    $("#fadeIn2").bind("click", slideDown2);
    $("#fadeOut2").bind("click", slideUp2);



    $('#teacherLogin').click(function() {

        let username = $("#teacherNum").val()
        let password = $("#teacherPaw").val()

        if (username && password) {
            $.ajax({
                url: "http://localhost:3001/login",
                dataType: "json",
                type: "post",
                data: { name: username, password },
                success: (res) => {
                    if (res.code == 200) {
                        alert("登录成功")
                        location.href = "/login"
                    } else {
                        alert(res.message)
                    }
                },
                error: (err) => {
                    console.log("fail", err)
                }
            })
        } else {
            alert("用户名密码不能为空")
        }
        return false
    })
})

function qq() {
    console.log('222');
    // $.get("http://loaclhost:3306/list", function(data, status) {
    //     console.log(data)
    // });
}

function slideDown() {
    $(".stu-register").slideDown(1000); //滑入
    $(".container-form").fadeOut(70);
}

function slideUp() {

    $(".stu-register").slideUp(1000, fadein); //滑出


}

function fadein() {
    $(".container-form").fadeIn(1100);
}
/////////////
function slideDown2() {
    $(".tea-register").slideDown(1000); //滑入
    $("#form2").fadeOut(70);

}

function slideUp2() {
    let username = $("#teacherRegisterNum").val()
    let password = $("#teacherRegisterPas").val()

    if (username && password) {
        $.ajax({
            url: "http://localhost:3001/register",
            dataType: "json",
            type: "post",
            data: { name: username, password },
            success: (res) => {
                if (res.code == 200) {
                    alert("注册成功")
                    location.href = "/login"
                } else {
                    alert(res.message)
                }
            },
            error: (err) => {
                console.log("fail", err)
            }
        })
    } else {
        alert("用户名密码不能为空")
    }



    $(".tea-register").slideUp(1000, fadein2); //滑出
    return false
}

function fadein2() {
    $("#form2").fadeIn(1100);
}

window.addEventListener('load', () => {

    const goSignIn = document.querySelector('#goSignIn');
    const goSignUp = document.querySelector('#goSignUp');

    const container = document.querySelector('.container');

    goSignIn.addEventListener('click', () => {
        container.classList.remove('switch');
    })
    goSignUp.addEventListener('click', () => {
        container.classList.add('switch');
    })
})